<?php 
namespace Admin\Controller;
use Think\Controller;

/**
 * 角色控制器
 */
class RolesController extends Controller {
	/**
	 * 权限列表
	 */
	public function index() {
		$m = D('Roles');
		$page = $m->queryByPage();

		$pager = new \Think\Page($page['total'],$page['pageSize']);// 实例化分页类 传入总记录数和每页显示的记录数
    	$page['pager'] = $pager->show();
    	$this->assign('Page',$page);
		$this->display("/roles/list");
	}

	/**
	 * 跳到新增、修改页面
	 */
	public function toEdit() {
		$m = D('Admin/Roles');
		$object = array();
		if (I('id',0)>0) {
			$object = $m->get();
		}else{
			$object = $m->getModel();
		}
		$this->assign('object',$object);
		$this->display("/roles/edit");
	}

	/**
	 * 新增、修改操作.收集数据
	 */
	public function edit() {
		$m = D('Roles');
		$rs = array('status'=>-1);
		if (I('id',0)>0) {
			$rs = $m->edit();
		}else{
			$rs = $m->insert();
		}
		$this->ajaxReturn($rs);
	}

	/**
	 * 删除操作
	 */
	public function del(){
		
		$m = D('Admin/Roles');
    	$rs = $m->del();
    	$this->ajaxReturn($rs);
	}


}
 ?>